import time
import tkinter as tk
from crawler import *
import numpy as np
class Window:
    def __init__(self, title='爬虫程序', width=300, height=192, staFunc=bool, stoFunc=bool):
        self.w = width
        self.h = height
        self.stat = True
        self.staFunc = staFunc
        self.stoFunc = stoFunc
        self.staIco = None
        self.stoIco = None
        self.root = tk.Tk(className=title)

    def center(self):
        ws = self.root.winfo_screenwidth()
        hs = self.root.winfo_screenheight()
        x = int( (ws/2) - (self.w/2) )
        y = int( (hs/2) - (self.h/2) )
        self.root.geometry('{}x{}+{}+{}'.format(self.w, self.h, x, y))

    def packBtn(self):
        # btnSer = tk.Button(self.root,text='爬取国内疫情数据',command=startGrasp, width=15, height=3).grid(row = 0,column  = 1)
        # # self.btnSer.pack(padx = 20,ipadx = 20)
        btnCenter = tk.Button(self.root,text = '生成国内疫情地图',command = drawMap,width = 20,height = 3).grid(row = 0,column = 1)

        btnWorld = tk.Button(self.root,text = '生成世界疫情地图',command = drawWorldMap,width = 20,height =3).grid(row = 0,column = 2)

        # btneveryday = tk.Button(self.root,text = '爬取国内每日数据',width = 15,height = 3).grid(row = 1,column  = 1)
        btneverydayDia = tk.Button(self.root,text = '国内疫情每日折线图',command = drawChinaLineChart,width = 20,height = 3).grid(row = 1, column = 1)

        # btnForeigner = tk.Button(self.root,text = '爬取国外疫情数据',width = 15,height = 3).grid(row = 2, column = 1)
        btnForeigner = tk.Button(self.root,text = '疫情严重国家top5统计图',width = 20,height = 3,command = drawWorldBar).grid(row = 1,column = 2)

        btnWordCloud = tk.Button(self.root,text = "生成新冠疫情词云",width = 20,height = 3 ,command = makeWordCloud).grid(row = 2,column = 1)


    def loop(self):
        self.root.resizable(False, False)   #禁止修改窗口大小
        self.packBtn()
        self.center()                       #窗口居中
        # self.event()
        self.root.mainloop()

########################################################################
def sta():
    print('start.')
    return True
def sto():
    print('stop.')
    return True

if __name__ == '__main__':
    import sys, os
    w = Window(staFunc=sta, stoFunc=sto)

    w.loop()